strip.background=element_blank(), strip.text.x = element_blank()) #Figure 2 (lower) and Figure 5 (lower)
synthdid_plot(estimates, facet.vertical=FALSE,
control.name='Synthetic rejection of\nTaiwan independence', treated.name='Actual rejection of\nTaiwan independence',
lambda.comparable=TRUE, se.method = 'none',
trajectory.linetype = 1, line.width=.75, effect.curvature=-.4,
trajectory.alpha=.7, effect.alpha=.7,
diagram.alpha=1, onset.alpha=.7) +
theme(legend.position=c(.10,.17), legend.direction='vertical',
legend.key=element_blank(), legend.background=element_blank(),
) + xlab("Date") +ylab("Standardised public opinion") #Figure 2 (upper) and Figure 5 (upper)
synthdid_units_plot(estimates, se.method='none') + labs(size="Weight:") +
theme(legend.background=element_blank(), legend.title = element_text(),
legend.direction='horizontal', legend.position=c(.17,.80),
strip.background=element_blank(), strip.text.x = element_blank()) #Figure 2 (lower) and Figure 5 (lower)
rm(list = ls()) # clear workspace
load("Taiwan_independence/59correction.Rdata")
#if you want to shorten the time period, do it here
merge <- subset(merge, period>=-20) #exclude data before 2011
merge$date <- merge$Date[merge$period==merge$period & merge$name=="indep_Taiwan"]
#use probit
merge$probit <- qnorm((merge$proBeijing/200)+0.5)
setup = panel.matrices(merge, unit = "name", time = "date", outcome = "probit", treatment = "treated")
tau.hat = synthdid_estimate(setup$Y, setup$N0, setup$T0)
plot <- plot(tau.hat, treated.name = "rejection of Taiwan independence", control.name = "synthetic rejection")
plot + xlab("periods") +ylab("standardised public opinion")
merge$omega [merge$name == merge$name [merge$treated==1][1]] <- 1
T1 <- length(merge$name[merge$treated==1])
merge$lambda [merge$period %in% merge$period[merge$treated==1]] <- 1/T1
omega.df <- data.frame(name = rownames(attributes(tau.hat)$setup$Y)[-nrow(attributes(tau.hat)$setup$Y)], omega = attributes(tau.hat)$weights$omega)
lambda.df <- data.frame(date = as.Date(colnames(attributes(tau.hat)$setup$Y)[1:(length(colnames(attributes(tau.hat)$setup$Y))-T1)]), lambda = attributes(tau.hat)$weights$lambda)
merge <- merge(merge, omega.df, by = "name", all = TRUE, no.dups = TRUE)
merge$omega <- ifelse(is.na(merge$omega.x),merge$omega.y,merge$omega.x)
merge <- subset(merge, select = -c(omega.x,omega.y))
merge <- merge(merge, lambda.df, by = "date", all = TRUE, no.dups = TRUE)
merge$lambda <- ifelse(is.na(merge$lambda.x),merge$lambda.y,merge$lambda.x)
merge <- subset(merge, select = -c(lambda.x, lambda.y))
merge$weights <- merge$lambda * merge$omega
merge <- merge[order(merge$name,merge$period,decreasing=TRUE),]
lm_sdid <- feols(probit ~ treated | name + period, data = merge, weights = merge$weights,
panel.id = ~name + period, vcov="DK")
lm_sdid_new <- feols(probit ~ treated | name + period, data = merge, weights = merge$weights,
panel.id = ~name + period, vcov="newey_west")
lm_sdid_clustered <- feols(probit ~ treated | name + period, data = merge, weights = merge$weights,
panel.id = ~name + period)
summary(lm_sdid_clustered)
#event study style plot #make sure the last weights calculation was for sdid
merge$time_to_treat = ifelse(merge$name=="indep_Taiwan" & merge$period>0, as.character(merge$date), '2020-01-03')
merge$treatment = ifelse(merge$name=="indep_Taiwan", 1, 0)
lm_ev <- feols(probit ~ i(time_to_treat, treated, ref='2020-01-03')| name + period,data = merge, weights = merge$weights,
panel.id = ~name + period)
iplot(lm_ev, ci_level = 0.95,
xlab = 'Time to treatment',
main = 'Event study: Staggered treatment (TWFE)') #an old-styled plot
ggiplot(lm_ev, ci_level = c(0.95, 0.90),geom_style = 'ribbon',
xlab = 'Time to treatment',
main = 'Event study style plot: Differential treatment effect over time \nPoll: Rejection of Taiwan independence',
theme = theme_minimal() +
theme(
plot.title = element_text(hjust = 0.5),
legend.position = 'none'
)) #Figure 6
rm(list = ls()) # clear workspace
setwd(gsub("/Tibet_independence","",dirname(rstudioapi::getSourceEditorContext()$path)))
list.files()
need <- c("foreign", "readstata13", "tidyverse", "estimatr", "csvy","synthdid", "modelsummary",
"devtools", "dplyr", "tidyr", "lubridate","fixest", "ggiplot") # list packages needed
have <- need %in% rownames(installed.packages()) # checks packages you have
if(any(!have)) install.packages(need[!have]) # install missing packages
invisible(lapply(need, library, character.only=T)) # load needed packages
load("Tibet_independence/59correction.Rdata")
#Date correction
merge$date <- merge$Date[merge$period==merge$period & merge$name=="indep_Tibet"]
#if you want to shorten the time period, do it here
merge <- subset(merge, period>=-23) #exclude data before 2010
merge$probit <- qnorm((merge$proBeijing/200)+0.5)
setup = panel.matrices(merge, unit = "name", time = "date", outcome = "probit", treatment = "treated")
tau.hat = synthdid_estimate(setup$Y, setup$N0, setup$T0)
plot <- plot(tau.hat, treated.name = "rejection of Tibet independence", control.name = "synthetic rejection")
plot + xlab("periods") +ylab("standardised public opinion")
synthdid_effect_curve(tau.hat)
synthdid_rmse_plot(tau.hat)
synthdid_units_plot(
list(SDID=tau.hat),
negligible.threshold = 0.001,
negligible.alpha = 0.3,
se.method = "none",
units = NULL
)
merge$omega [merge$name == merge$name [merge$treated==1][1]] <- 1
T1 <- length(merge$name[merge$treated==1])
merge$lambda [merge$period %in% merge$period[merge$treated==1]] <- 1/T1
omega.df <- data.frame(name = rownames(attributes(tau.hat)$setup$Y)[-nrow(attributes(tau.hat)$setup$Y)], omega = attributes(tau.hat)$weights$omega)
lambda.df <- data.frame(date = as.Date(colnames(attributes(tau.hat)$setup$Y)[1:(length(colnames(attributes(tau.hat)$setup$Y))-T1)]), lambda = attributes(tau.hat)$weights$lambda)
merge <- merge(merge, omega.df, by = "name", all = TRUE, no.dups = TRUE)
merge$omega <- ifelse(is.na(merge$omega.x),merge$omega.y,merge$omega.x)
merge <- subset(merge, select = -c(omega.x,omega.y))
merge <- merge(merge, lambda.df, by = "date", all = TRUE, no.dups = TRUE)
merge$lambda <- ifelse(is.na(merge$lambda.x),merge$lambda.y,merge$lambda.x)
merge <- subset(merge, select = -c(lambda.x, lambda.y))
merge$weights <- merge$lambda * merge$omega
merge <- merge[order(merge$name,merge$period,decreasing=TRUE),]
lm_sdid <- feols(probit ~ treated | name + period, data = merge, weights = merge$weights,
panel.id = ~name + period, vcov="DK")
lm_sdid_new <- feols(probit ~ treated | name + period, data = merge, weights = merge$weights,
panel.id = ~name + period, vcov="newey_west")
lm_sdid_clustered <- feols(probit ~ treated | name + period, data = merge, weights = merge$weights,
panel.id = ~name + period)
summary(lm_sdid_clustered)
#event study style plot #make sure the last weights calculation was for sdid
merge$time_to_treat = ifelse(merge$name=="indep_Tibet" & merge$period>0,as.character(merge$date), '2020-01-03')
merge$treatment = ifelse(merge$name=="indep_Tibet", 1, 0)
lm_ev <- feols(probit ~ i(time_to_treat, treated, ref='2020-01-03')| name + period,data = merge, weights = merge$weights,
panel.id = ~name + period)
iplot(lm_ev, ci_level = 0.95,
xlab = 'Time to treatment',
main = 'Event study: Staggered treatment (TWFE)') #an old-styled plot
ggiplot(lm_ev, ci_level = c(0.95, 0.90),geom_style = 'ribbon',
xlab = 'Time to treatment',
main = 'Event study style plot: Differential treatment effect over time \nPoll: Rejection of Tibet independence',
theme = theme_minimal() +
theme(
plot.title = element_text(hjust = 0.5),
legend.position = 'none'
)) #Figure 8
tau.hat.did <- did_estimate(setup$Y, setup$N0, setup$T0)
tau.hat.sc <- sc_estimate(setup$Y, setup$N0, setup$T0)
estimates = list(tau.hat.did, tau.hat.sc, tau.hat)
names(estimates) = c('Diff-in-Diff', 'Synthetic Control', 'Synthetic Diff-in-Diff')
synthdid_plot(estimates, facet.vertical=FALSE,
control.name='Synthetic public opinion', treated.name='Actual public opnion',
lambda.comparable=TRUE, se.method = 'none',
trajectory.linetype = 1, line.width=.75, effect.curvature=-.4,
trajectory.alpha=.7, effect.alpha=.7,
diagram.alpha=1, onset.alpha=.7) +
theme(legend.position=c(.10,.15), legend.direction='vertical',
legend.key=element_blank(), legend.background=element_blank(),
) + xlab("Date") +ylab("Standardised public opinion") #Figure 7 (upper)
synthdid_units_plot(estimates, se.method='none') + labs(size="Weight:") +
theme(legend.background=element_blank(), legend.title = element_text(),
legend.direction='horizontal', legend.position=c(.17,.80),
strip.background=element_blank(), strip.text.x = element_blank())  #Figure 7 (lower)
rm(list = ls()) # clear workspace
need <- c("foreign", "readstata13", "tidyverse", "estimatr", "csvy","synthdid", "modelsummary",
"devtools", "dplyr", "tidyr", "lubridate","fixest", "ggiplot") # list packages needed
have <- need %in% rownames(installed.packages()) # checks packages you have
if(any(!have)) install.packages(need[!have]) # install missing packages
invisible(lapply(need, library, character.only=T)) # load needed packages
#######################Pre-treatment tests for 2008################################
#Taiwan independence
setwd(gsub("/Taiwan_independence","",dirname(rstudioapi::getSourceEditorContext()$path)))
load("Taiwan_independence/59correction.Rdata")
merge$date <- merge$Date[merge$period==merge$period & merge$name=="indep_Taiwan"]
merge <- subset(merge, period<=0)
merge$treated[merge$name=="indep_Taiwan" & merge$period>-30] <- 1
merge$probit <- qnorm((merge$proBeijing/200)+0.5)
setup = panel.matrices(merge, unit = "name", time = "date", outcome = "probit", treatment = "treated")
tau.hat.Taiwan = synthdid_estimate(setup$Y, setup$N0, setup$T0)
#Tibet independence
setwd(gsub("/Tibet_independence","",dirname(rstudioapi::getSourceEditorContext()$path)))
load("Tibet_independence/59correction.Rdata")
merge$date <- merge$Date[merge$period==merge$period & merge$name=="indep_Tibet"]
merge <- subset(merge, period<=0)
merge$treated[merge$name=="indep_Tibet" & merge$period>=-30] <- 1
merge$probit <- qnorm((merge$proBeijing/200)+0.5)
setup = panel.matrices(merge, unit = "name", time = "date", outcome = "probit", treatment = "treated")
tau.hat.Tibet = synthdid_estimate(setup$Y, setup$N0, setup$T0)
#June Fourth (Tiananmen Incident)
setwd(gsub("/64","",dirname(rstudioapi::getSourceEditorContext()$path)))
load("64/59correction.Rdata")
merge$date <- merge$Date[merge$period==merge$period & merge$name=="64_students"]
merge <- subset(merge, period<=0)
merge$treated[merge$name %in% treat_list & merge$period>-12] <- 1
merge$probit <- qnorm((merge$proBeijing/200)+0.5)
setup = panel.matrices(merge, unit = "name", time = "date", outcome = "probit", treatment = "treated")
tau.hat.64 = synthdid_estimate(setup$Y, setup$N0, setup$T0)
#Plot three results
estimates = list(tau.hat.Taiwan, tau.hat.Tibet, tau.hat.64)
names(estimates) = c('Rejection of Taiwan independence', 'Rejection of Tibet independence', 'Support for Beijing on June Fourth incident')
synthdid_plot(estimates, facet.vertical=FALSE,
control.name='Synthetic public opinion', treated.name='Actual public opinion',
lambda.comparable=TRUE, se.method = 'none',
trajectory.linetype = 1, line.width=.75, effect.curvature=-.4,
trajectory.alpha=.7, effect.alpha=.7,
diagram.alpha=1, onset.alpha=.7) +
theme(legend.position=c(.23,.20), legend.direction='vertical',
legend.key=element_blank(), legend.background=element_blank(),
) + xlab("Date") +ylab("Standardised public opinion") +ggtitle("Trend tests for pre and post-2008") #Figure 3
rm(list = ls()) # clear workspace
#Taiwan independence
setwd(gsub("/Taiwan_independence","",dirname(rstudioapi::getSourceEditorContext()$path)))
load("Taiwan_independence/59correction.Rdata")
merge$date <- merge$Date[merge$period==merge$period & merge$name=="indep_Taiwan"]
merge <- subset(merge, period<=0)
merge$treated[merge$name=="indep_Taiwan" & merge$period>-30] <- 1
merge$probit <- qnorm((merge$proBeijing/200)+0.5)
merge <- subset(merge, period>-30)
merge$treated[merge$name=="indep_Taiwan" & merge$period<=-10] <- 0
setup = panel.matrices(merge, unit = "name", time = "date", outcome = "probit", treatment = "treated")
tau.hat.Taiwan = synthdid_estimate(setup$Y, setup$N0, setup$T0)
#Tibet independence
setwd(gsub("/Tibet_independence","",dirname(rstudioapi::getSourceEditorContext()$path)))
load("Tibet_independence/59correction.Rdata")
merge$date <- merge$Date[merge$period==merge$period & merge$name=="indep_Tibet"]
merge <- subset(merge, period<=0)
merge$treated[merge$name=="indep_Tibet" & merge$period>=-30] <- 1
merge$probit <- qnorm((merge$proBeijing/200)+0.5)
merge <- subset(merge, period>=-23)
merge$treated[merge$name=="indep_Tibet" & merge$period<(-10)] <- 0
setup = panel.matrices(merge, unit = "name", time = "date", outcome = "probit", treatment = "treated")
tau.hat.Tibet = synthdid_estimate(setup$Y, setup$N0, setup$T0)
#June Fourth (Tiananmen Incident)
setwd(gsub("/64","",dirname(rstudioapi::getSourceEditorContext()$path)))
load("64/59correction.Rdata")
merge$date <- merge$Date[merge$period==merge$period & merge$name=="64_students"]
merge <- subset(merge, period<=0)
merge$treated[merge$name %in% treat_list & merge$period>-12] <- 1
merge$probit <- qnorm((merge$proBeijing/200)+0.5)
merge <- subset(merge, period>=-10)
merge$treated[merge$name %in% treat_list & merge$period<=-6] <- 0
setup = panel.matrices(merge, unit = "name", time = "date", outcome = "probit", treatment = "treated")
tau.hat.64 = synthdid_estimate(setup$Y, setup$N0, setup$T0)
#Plot three results
estimates = list(tau.hat.Taiwan, tau.hat.Tibet, tau.hat.64)
names(estimates) = c('Rejection of Taiwan independence', 'Rejection of Tibet independence', 'Support for Beijing on June Fourth incident')
synthdid_plot(estimates, facet.vertical=FALSE,
control.name='Synthetic public opinion', treated.name='Actual public opinion',
lambda.comparable=TRUE, se.method = 'none',
trajectory.linetype = 1, line.width=.75, effect.curvature=-.4,
trajectory.alpha=.7, effect.alpha=.7,
diagram.alpha=1, onset.alpha=.7) +
theme(legend.position=c(.09,.26), legend.direction='vertical',
legend.key=element_blank(), legend.background=element_blank(),
) + xlab("Date") +ylab("Standardised public opinion") +ggtitle("Trend tests for pre and post-2015") #Figure 4
# Generate a sequence of numbers from -4 to 4 with increments of 0.1
x <- seq(-4, 4, by = 0.1)
y <- dnorm(x, mean = 0, sd = 1)
df <- data.frame(x = x, y = y)
# Create the plot using ggplot
ggplot(data = df, aes(x = x, y = y)) +
geom_line() +
scale_x_continuous(breaks = seq(-4, 4, by = 1), limits = c(-4, 4)) +
scale_y_continuous(limits = c(0, 0.4)) +
labs(x = "Public Opinion", y = "PDF", title = "Normal Distribution, μ=0, σ=1, γ=0.5") +
theme_bw() +
theme(plot.title = element_text(hjust = 0.5)) +
geom_vline(xintercept = 0.5, linetype = "solid", color = "red") +
annotate("text", x = 2, y = 0.07, label = "x", hjust = 0)+
annotate("text", x = 0.6, y = 0.02, label = "γ", color = "red", hjust = 0) +
geom_vline(xintercept = 0, linetype = "dashed", color = "blue")+
annotate("text", x = 4, y = 0.03, label = "Pro-Beijing", hjust = 1) +
annotate("text", x = -4, y = 0.03, label = "Anti-Beijing", hjust = 0) +
geom_segment(aes(x = 0, y = 0.02, xend = 0.5, yend = 0.02), linetype = "dashed", color = "blue")+
annotate("text", x = 0.04, y = 0.03, label = "(μ-γ)", color = "blue", hjust = 0)
rm(list=ls())
need <- c("ggplot2", "dplyr", "grid") # list packages needed
have <- need %in% rownames(installed.packages()) # checks packages you have
if(any(!have)) install.packages(need[!have]) # install missing packages
invisible(lapply(need, library, character.only=T)) # load needed packages
x <- seq(-4, 4, by = 0.1)
y <- dnorm(x, mean = 0, sd = 1)
df <- data.frame(x = x, y = y)
# Create the plot using ggplot
ggplot(data = df, aes(x = x, y = y)) +
geom_line() +
scale_x_continuous(breaks = seq(-4, 4, by = 1), limits = c(-4, 4)) +
scale_y_continuous(limits = c(0, 0.4)) +
labs(x = "Public Opinion", y = "PDF", title = "Normal Distribution, μ=0, σ=1, γ=0.5") +
theme_bw() +
theme(plot.title = element_text(hjust = 0.5)) +
geom_vline(xintercept = 0.5, linetype = "solid", color = "red") +
annotate("text", x = 2, y = 0.07, label = "x", hjust = 0)+
annotate("text", x = 0.6, y = 0.02, label = "γ", color = "red", hjust = 0) +
geom_vline(xintercept = 0, linetype = "dashed", color = "blue")+
annotate("text", x = 4, y = 0.03, label = "Pro-Beijing", hjust = 1) +
annotate("text", x = -4, y = 0.03, label = "Anti-Beijing", hjust = 0) +
geom_segment(aes(x = 0, y = 0.02, xend = 0.5, yend = 0.02), linetype = "dashed", color = "blue")+
annotate("text", x = 0.04, y = 0.03, label = "(μ-γ)", color = "blue", hjust = 0)
x2 <- seq(-4, 4, by = 0.1)
y2 <- dnorm(x2, mean = 1, sd = 1)
df2 <- data.frame(x = x2, y = y2)
ggplot() +
geom_line(data = df, aes(x = x, y = y), color="black") +
geom_line(data = df2, aes(x = x, y = y), color = "blue") +
scale_x_continuous(breaks = seq(-4, 4, by = 1), limits = c(-4, 4)) +
scale_y_continuous(limits = c(0, 0.4)) +
labs(x = "Public Opinion", y = "PDF", title = "Normal Distribution, μ=0→1, σ=1, γ=0.5") +
theme_bw() +
theme(plot.title = element_text(hjust = 0.5)) +
geom_vline(xintercept = 0.5, linetype = "solid", color = "red") +
annotate("text", x = 2, y = 0.07, label = "x1", hjust = 0)+
annotate("text", x = 3, y = 0.07, label = "x2", hjust = 0, color="blue")+
annotate("text", x = 0.6, y = 0.1, label = "γ", color = "red", hjust = 0) +
geom_vline(xintercept = 0, linetype = "dashed", color = "blue")+
geom_vline(xintercept = 1, linetype = "dashed", color = "blue")+
annotate("text", x = 4, y = 0.03, label = "Pro-Beijing", hjust = 1) +
annotate("text", x = -4, y = 0.03, label = "Anti-Beijing", hjust = 0) +
geom_segment(aes(x = 0, y = 0.02, xend = 1, yend = 0.02), linetype = "dashed", color = "blue")+
annotate("text", x = 0.3, y = 0.03, label = "△(μ-γ)", color = "blue", hjust = 0)
x3 <- seq(-2, 6, by = 0.1)
y3 <- dnorm(x3, mean = 2, sd = 1)
df3 <- data.frame(x = x3, y = y3)
x4 <- seq(-2, 6, by = 0.1)
y4 <- dnorm(x3, mean = 3, sd = 1)
df4 <- data.frame(x = x4, y = y4)
ggplot() +
geom_line(data = df3, aes(x = x, y = y), color="black") +
geom_line(data = df4, aes(x = x, y = y), color = "blue") +
scale_x_continuous(breaks = seq(-4, 4, by = 1), limits = c(-2, 6)) +
scale_y_continuous(limits = c(0, 0.4)) +
labs(x = "Public Opinion", y = "PDF", title = "Normal Distribution, μ=2→3, σ=1, γ=0.5") +
theme_bw() +
theme(plot.title = element_text(hjust = 0.5)) +
geom_vline(xintercept = 0.5, linetype = "solid", color = "red") +
annotate("text", x = 4, y = 0.07, label = "x1", hjust = 0)+
annotate("text", x = 5, y = 0.07, label = "x2", hjust = 0, color="blue")+
annotate("text", x = 0.6, y = 0.08, label = "γ", color = "red", hjust = 0) +
geom_vline(xintercept = 2, linetype = "dashed", color = "blue")+
geom_vline(xintercept = 3, linetype = "dashed", color = "blue")+
annotate("text", x = 6, y = 0.03, label = "Pro-Beijing", hjust = 1) +
annotate("text", x = -2, y = 0.03, label = "Anti-Beijing", hjust = 0) +
geom_segment(aes(x = 2, y = 0.02, xend = 3, yend = 0.02), linetype = "dashed", color = "blue")+
annotate("text", x = 2.3, y = 0.03, label = "△(μ-γ)", color = "blue", hjust = 0)
##################Figure B4#########################
x2 <- seq(-3, 5, by = 0.1)
y2 <- dnorm(x2, mean = 1, sd = 1)
df2 <- data.frame(x = x2, y = y2)
x2s <- seq(-3, 5, by = 0.1)
y2s <- dnorm(x2s, mean = 1, sd = 0.5)
df2s <- data.frame(x = x2s, y = y2s)
ggplot() +
geom_line(data = df2, aes(x = x, y = y), color="black") +
geom_line(data = df2s, aes(x = x, y = y), color = "blue") +
scale_x_continuous(breaks = seq(-3, 5, by = 1), limits = c(-3, 5)) +
scale_y_continuous(limits = c(0, 0.8)) +
labs(x = "Public Opinion", y = "PDF", title = "Normal Distribution, μ=1, σ=1→0.5, γ=0.5") +
theme_bw() +
theme(plot.title = element_text(hjust = 0.5)) +
geom_vline(xintercept = 0.5, linetype = "solid", color = "red") +
annotate("text", x = 3, y = 0.07, label = "x1", hjust = 0)+
annotate("text", x = 2.3, y = 0.07, label = "x2", hjust = 0, color="blue")+
annotate("text", x = 0.6, y = 0.07, label = "γ", color = "red", hjust = 0) +
geom_vline(xintercept = 1, linetype = "dashed", color = "blue")+
annotate("text", x = 4, y = 0.03, label = "Pro-Beijing", hjust = 1) +
annotate("text", x = -4, y = 0.03, label = "Anti-Beijing", hjust = 0)
x4 <- seq(-2, 6, by = 0.1)
y4 <- dnorm(x3, mean = 3, sd = 1)
df4 <- data.frame(x = x4, y = y4)
x4s <- seq(-2, 6, by = 0.1)
y4s <- dnorm(x3, mean = 3, sd = 0.5)
df4s <- data.frame(x = x4s, y = y4s)
ggplot() +
geom_line(data = df4, aes(x = x, y = y), color = "black") +
geom_line(data = df4s, aes(x = x, y = y), color = "blue") +
scale_x_continuous(breaks = seq(-4, 4, by = 1), limits = c(-2, 6)) +
scale_y_continuous(limits = c(0, 0.8)) +
labs(x = "Public Opinion", y = "PDF", title = "Normal Distribution, μ=3, σ=1→0.5, γ=0.5") +
theme_bw() +
theme(plot.title = element_text(hjust = 0.5)) +
geom_vline(xintercept = 0.5, linetype = "solid", color = "red") +
annotate("text", x = 5, y = 0.07, label = "x1", hjust = 0)+
annotate("text", x = 4.3, y = 0.07, label = "x2", hjust = 0, color="blue")+
annotate("text", x = 0.6, y = 0.08, label = "γ", color = "red", hjust = 0) +
geom_vline(xintercept = 3, linetype = "dashed", color = "blue")+
annotate("text", x = 6, y = 0.03, label = "Pro-Beijing", hjust = 1) +
annotate("text", x = -2, y = 0.03, label = "Anti-Beijing", hjust = 0)
#setup
rm(list = ls()) # clear workspace
need <- c("foreign",  "tidyverse",  "csvy",
"devtools", "dplyr", "tidyr", "lubridate", "ggiplot") # list packages needed
have <- need %in% rownames(installed.packages()) # checks packages you have
if(any(!have)) install.packages(need[!have]) # install missing packages
invisible(lapply(need, library, character.only=T)) # load needed packages
rm(list = ls()) # clear workspace
setwd(gsub("/Taiwan_independence","",dirname(rstudioapi::getSourceEditorContext()$path)))
list.files()
load("Taiwan_independence/merged.Rdata")
list.files()
setwd(gsub("/Taiwan_independence","",dirname(rstudioapi::getSourceEditorContext()$path)))
list.files()
gsub("/Taiwan_independence","",dirname(rstudioapi::getSourceEditorContext()$path))
load(paste0("cleaned data/","appraisal_civilization",".Rdata"))
dirname(rstudioapi::getSourceEditorContext()$path)
rm(list = ls()) # clear workspace
setwd(gsub("/Taiwan_independence","",dirname(rstudioapi::getSourceEditorContext()$path)))
list.files()
load("Taiwan_independence/merged.Rdata")
load(paste0("cleaned data/","appraisal_civilization",".Rdata"))
a <- subset(a, select=c(Date, proBeijing, sensitivity))
a$name <- "appraisal_civilization"
a$treated <- 0
appraisal_civilization <- a
rm(a)
indep_Taiwan <- subset(indep_Taiwan, select=-period)
merge_demo <- rbind(indep_Taiwan[1:7,], appraisal_civilization[1:9,])
ggplot(data=merge_demo)+geom_line(aes(x=Date, y=proBeijing, color=name))+
geom_vline(data=merge_demo[1:7,], aes(xintercept=Date), linetype="dashed", color="black")+
xlab("Date")+ylab("Unstandardised support for Beijing")+ggtitle("Unaligned poll data demo")
load("Taiwan_independence/59correction.Rdata")
merge <- rbind(merge[1:7,],merge[73:79,])
ggplot(data=merge)+geom_line(aes(x=Date, y=proBeijing, color=name))+
geom_vline(data=merge_demo[1:7,], aes(xintercept=Date), linetype="dashed", color="black")+
xlab("Date")+ylab("Unstandardised support for Beijing")+ggtitle("Unaligned poll data demo (trimmed)")
merge$date <- merge$Date[merge$period==merge$period & merge$name=="indep_Taiwan"]
ggplot(data=merge)+geom_line(aes(x=date, y=proBeijing, color=name))+
geom_vline(data=merge_demo[1:7,], aes(xintercept=Date), linetype="dashed", color="black")+
xlab("Date")+ylab("Unstandardised support for Beijing")+ggtitle("Aligned poll data demo")
rm(list = ls()) # clear workspace
need <- c("foreign",  "tidyverse",  "csvy",
"devtools", "dplyr", "tidyr", "lubridate", "ggiplot") # list packages needed
have <- need %in% rownames(installed.packages()) # checks packages you have
if(any(!have)) install.packages(need[!have]) # install missing packages
invisible(lapply(need, library, character.only=T)) # load needed packages
rm(list = ls()) # clear workspace
setwd(gsub("/Taiwan_independence","",dirname(rstudioapi::getSourceEditorContext()$path)))
list.files()
load("Taiwan_independence/merged.Rdata")
load(paste0("cleaned data/","appraisal_civilization",".Rdata"))
a <- subset(a, select=c(Date, proBeijing, sensitivity))
a$name <- "appraisal_civilization"
a$treated <- 0
appraisal_civilization <- a
rm(a)
indep_Taiwan <- subset(indep_Taiwan, select=-period)
merge_demo <- rbind(indep_Taiwan[1:7,], appraisal_civilization[1:9,])
ggplot(data=merge_demo)+geom_line(aes(x=Date, y=proBeijing, color=name))+
geom_vline(data=merge_demo[1:7,], aes(xintercept=Date), linetype="dashed", color="black")+
xlab("Date")+ylab("Unstandardised support for Beijing")+ggtitle("Unaligned poll data demo")
rm(list = ls()) # clear workspace
load("Taiwan_independence/merged.Rdata")
View(merge)
load(paste0("cleaned data/","appraisal_civilization",".Rdata"))
View(indep_Taiwan)
setwd(gsub("/Taiwan_independence","",dirname(rstudioapi::getSourceEditorContext()$path)))
load("Taiwan_independence/59correction.Rdata")
setwd(gsub("/Taiwan_independence","",dirname(rstudioapi::getSourceEditorContext()$path)))
load("Taiwan_independence/merged.Rdata")
rm(list = ls()) # clear workspace
load("Taiwan_independence/merged.Rdata")
View(merge)
load("Taiwan_independence/59correction.Rdata")
View(indep_Taiwan)
load("Taiwan_independence/merged.Rdata")
View(merge)
load("Taiwan_independence/59correction.Rdata")
View(merge)
load("Taiwan_independence/merged.Rdata")
load("Taiwan_independence/59correction.Rdata")
load(paste0("cleaned data/","appraisal_civilization",".Rdata"))
a <- subset(a, select=c(Date, proBeijing, sensitivity))
a$name <- "appraisal_civilization"
a$treated <- 0
appraisal_civilization <- a
rm(a)
indep_Taiwan <- subset(indep_Taiwan, select=-period)
merge_demo <- rbind(indep_Taiwan[1:7,], appraisal_civilization[1:9,])
ggplot(data=merge_demo)+geom_line(aes(x=Date, y=proBeijing, color=name))+
geom_vline(data=merge_demo[1:7,], aes(xintercept=Date), linetype="dashed", color="black")+
xlab("Date")+ylab("Unstandardised support for Beijing")+ggtitle("Unaligned poll data demo")
rm(list = ls()) # clear workspace
load("Taiwan_independence/59correction.Rdata")
load(paste0("cleaned data/","appraisal_civilization",".Rdata"))
a <- subset(a, select=c(Date, proBeijing, sensitivity))
a$name <- "appraisal_civilization"
a$treated <- 0
appraisal_civilization <- a
rm(a)
indep_Taiwan <- subset(indep_Taiwan, select=-period)
merge_demo <- rbind(indep_Taiwan[1:7,], appraisal_civilization[1:9,])
ggplot(data=merge_demo)+geom_line(aes(x=Date, y=proBeijing, color=name))+
geom_vline(data=merge_demo[1:7,], aes(xintercept=Date), linetype="dashed", color="black")+
xlab("Date")+ylab("Unstandardised support for Beijing")+ggtitle("Unaligned poll data demo")
rm(list = ls()) # clear workspace
need <- c("foreign",  "tidyverse",  "csvy",
"devtools", "dplyr", "tidyr", "lubridate", "ggiplot") # list packages needed
have <- need %in% rownames(installed.packages()) # checks packages you have
if(any(!have)) install.packages(need[!have]) # install missing packages
invisible(lapply(need, library, character.only=T)) # load needed packages
rm(list = ls()) # clear workspace
setwd(gsub("/Taiwan_independence","",dirname(rstudioapi::getSourceEditorContext()$path)))
list.files()
load("Taiwan_independence/59correction.Rdata")
load(paste0("cleaned data/","appraisal_civilization",".Rdata"))
a <- subset(a, select=c(Date, proBeijing, sensitivity))
a$name <- "appraisal_civilization"
a$treated <- 0
appraisal_civilization <- a
rm(a)
indep_Taiwan <- subset(indep_Taiwan, select=-period)
merge_demo <- rbind(indep_Taiwan[1:7,], appraisal_civilization[1:9,])
ggplot(data=merge_demo)+geom_line(aes(x=Date, y=proBeijing, color=name))+
geom_vline(data=merge_demo[1:7,], aes(xintercept=Date), linetype="dashed", color="black")+
xlab("Date")+ylab("Unstandardised support for Beijing")+ggtitle("Unaligned poll data demo")
merge <- rbind(merge[1:7,],merge[73:79,])
ggplot(data=merge)+geom_line(aes(x=Date, y=proBeijing, color=name))+
geom_vline(data=merge_demo[1:7,], aes(xintercept=Date), linetype="dashed", color="black")+
xlab("Date")+ylab("Unstandardised support for Beijing")+ggtitle("Unaligned poll data demo (trimmed)")
merge$date <- merge$Date[merge$period==merge$period & merge$name=="indep_Taiwan"]
ggplot(data=merge)+geom_line(aes(x=date, y=proBeijing, color=name))+
geom_vline(data=merge_demo[1:7,], aes(xintercept=Date), linetype="dashed", color="black")+
xlab("Date")+ylab("Unstandardised support for Beijing")+ggtitle("Aligned poll data demo")
load("Taiwan_independence/59correction.Rdata")
load(paste0("cleaned data/","appraisal_civilization",".Rdata"))
a <- subset(a, select=c(Date, proBeijing, sensitivity))
a$name <- "appraisal_civilization"
a$treated <- 0
appraisal_civilization <- a
rm(a)
indep_Taiwan <- subset(indep_Taiwan, select=-period)
merge_demo <- rbind(indep_Taiwan[1:7,], appraisal_civilization[1:9,])
ggplot(data=merge_demo)+geom_line(aes(x=Date, y=proBeijing, color=name))+
geom_vline(data=merge_demo[1:7,], aes(xintercept=Date), linetype="dashed", color="black")+
xlab("Date")+ylab("Unstandardised support for Beijing")+ggtitle("Unaligned poll data demo")
